using System;
using System.IO;
using CodePlex.TfsLibrary.ObjectModel;

namespace CodePlex.CodePlexClientLibrary
{
    [Command("delete", "Schedule files and/or directories for delete.", MinArgs = 1, AltName = "del", UsageSummary = "<path...> [options]",
        UsageDescription = @"Schedules files and/or directories for delete during the next commit. If
any contained or provided path contains modified or unversioned items, they
will not be removed (unless you specify the /force option).

The first column contains delete information:
  D  File/folder scheduled for deletion
  F  Unversioned file/folder force deleted")]
    public class DeleteCommand : NonAuthenticatedCommand
    {
        bool force;

        [Option("force", "force delete to run", ShortName = "f")]
        public bool Force
        {
            get { return force; }
            set { force = value; }
        }

        public override void Execute()
        {
            foreach (string path in Arguments)
                Engine.Delete(CodePlexClientUtil.GetFullPath(path), Force, OnSourceItem);
        }

        static void OnSourceItem(SourceItem item,
                                 SourceItemResult result)
        {
            string itemName = CodePlexClientUtil.GetRelativePath(Directory.GetCurrentDirectory(), item.LocalName);

            switch (result)
            {
                case SourceItemResult.S_Ok:
                    Console.WriteLine("D    {0}", itemName);
                    break;

                case SourceItemResult.S_ForcedDelete:
                    if (item.LocalItemStatus == SourceItemStatus.Delete)
                        Console.WriteLine("D    {0}", itemName);
                    else
                        Console.WriteLine("F    {0}", itemName);
                    break;

                default:
                    ConsoleUtil.PrintCommandError(itemName, result);
                    break;
            }
        }
    }
}